package org.example.util;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeewx.api.core.exception.WexinReqException;
import org.jeewx.api.core.req.WeiXinReqService;
import org.jeewx.api.core.req.model.AccessToken;
import org.jeewx.api.wxbase.wxtoken.JwTokenAPI;
import org.jeewx.api.wxsendmsg.JwSendTemplateMsgAPI;
import org.jeewx.api.wxuser.user.JwUserAPI;
import org.jeewx.api.wxuser.user.model.Wxuser;

@Slf4j
public class WxUtil {

    private static String appid = "wxec699e9d91368f2a";
    private static String appscret = "17edf5f563999b2bc4468bc03d556622";

    private static AccessToken atoken = null;

    public static Wxuser getUser() throws WexinReqException {
        //String accessToken = JwTokenAPI.getAccessToken(appid, appscret);
        atoken = new AccessToken();
        atoken.setAppid(appid);
        atoken.setSecret(appscret);
        JSONObject result = WeiXinReqService.getInstance().doWeinxinReqJson(atoken);
        System.out.println(result.toString());
        String accessToken = result.getString("access_token");
        String openid = result.getString("openid");
        Wxuser wxuser = JwUserAPI.getWxuser(accessToken, openid);
        return wxuser;
    }

    public static String getAccessToken() throws WexinReqException {
        String accessToken = JwTokenAPI.getAccessToken(appid, appscret);
        return accessToken;
    }



    public static void main(String[] args) throws WexinReqException {
        String accessToken = getAccessToken();
        String templateId = JwSendTemplateMsgAPI.getTemplateId(accessToken);
        System.out.println(templateId);
    }


}
